﻿<%@ Page Title="店铺货架明细" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet" />
    <link href="../assets/css/shelf/base.css" rel="stylesheet" />
    <link href="../assets/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet" />
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet" />
    <style type="text/css">
        .module-info .control-label {
            float: left;
            text-align: right;
            min-width: 110px;
        }

        @media (min-width: 528px) {
            .modal-dialog {
                width: 508px;
                margin: 5px auto;
            }
        }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container"></div>
            <div class="condition">
                <label>搜索关键字</label>
                <input class="form-control input-w170 search-keys" placeholder="店铺(货架)编号或名称" />
                <label>是否有效</label>
                <select id="isRemove" class="form-control input-w160">
                    <option value="-1">全部</option>
                    <option value="0">有效</option>
                    <option value="1">无效</option>
                </select>
            </div>
            <div class="right-content-box">
                <div class="ibox-content">
                    <table class="footable table table-stripped">
                        <thead></thead>
                        <tbody id="pageList"></tbody>
                    </table>
                </div>
            </div>

            <div class="pageControl"></div>
        </div>
    </div>

    <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
        <form id="checkModuleForm" method="get" action="#">
            <div class="modal-dialog">
                <div class="modal-content animated bounceInRight">
                    <div class="modal-header">
                        <span class="editTitle">店铺货架明细</span>
                        <button type="button" class="close" data-dismiss="modal">
                            <span aria-hidden="true">&times;</span>
                            <span class="sr-only">关闭</span>
                        </button>
                    </div>
                    <div id="message" style="display: none"></div>
                    <div class="modal-body">
                        <table class="module-info" cellpadding="0" cellspacing="0">
                            <thead></thead>
                            <tbody>
                                <tr>
                                    <td colspan="2">
                                        <div class="form-group">
                                            <label class="control-label">店铺名称<span class="must-sign">*</span></label>
                                            <input id="shopSearch" name="shopSearch" maxlength="100"
                                                datacol="yes" err="店铺名称" checkexpession="NotNull"
                                                placeholder="请输入店铺名称或编号" class="form-control input-w320" />
                                            <input id="ShopName" name="ShopName" type="hidden" />
                                            <input id="ShopCode" name="ShopCode" type="hidden" />
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <div class="form-group">
                                            <label class="control-label">货架<span class="must-sign">*</span></label>
                                            <input type="hidden" id="GSID" name="GSID" />
                                            <input id="GSText" name="GSText" placeholder="请输入货架名称或编号"
                                                datacol="yes" err="货架" checkexpession="NotNull"
                                                maxlength="20" class="form-control input-w320" />
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <div class="form-group">
                                            <label class="control-label">货架数量<span class="must-sign">*</span></label>
                                            <input id="Qty" type="number" name="Qty" placeholder="请输入货架数量"
                                                datacol="yes" err="货架数量" checkexpession="NotNull"
                                                maxlength="5" class="form-control input-w320" />
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
                        <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/plugins/fancybox/jquery.fancybox.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script type="application/javascript">
        $(document).ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //初始化图片展示
            $(".fancybox").fancybox({
                openEffect: "none",
                closeEffect: "none"
            });

            //自动填充(商店)
            $('#shopSearch').typeahead({
                source: function (query, process) {
                    var parameter = { query: query };
                    $('#ShopName').val('');
                    $('#ShopCode').val('');
                    Y.API2('Shop', 'GetShopBaseInfo', {
                        GetAllList: "True",
                        Keys: $('#shopSearch').val()
                    }, function (data) {
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            var results = data.map(function (item) {
                                return JSON.stringify(item);
                            })
                            process(results);
                        }
                    });
                },
                highlighter: function (item) {
                    var item = JSON.parse(item);
                    return '名称：' + item.ShopName + '　编号：' + item.ShopCode;
                },
                updater: function (item) {
                    var item = JSON.parse(item);
                    $('#ShopName').val(item.ShopName);
                    $('#ShopCode').val(item.ShopCode);
                    return item.ShopName;
                }
            });

            //自动填充(货架)
            $('#GSText').typeahead({
                source: function (query, process) {
                    var parameter = { query: query };
                    $('#GSID').val('');
                    Y.API2('GoodShelf', 'List', {
                        Keys: $('#GSText').val()
                    }, function (data) {
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            var results = data.Items.map(function (item) {
                                return JSON.stringify(item);
                            })
                            process(results);
                        }
                    });
                },
                highlighter: function (item) {
                    var item = JSON.parse(item);
                    return '名称：' + item.GSName + '　编号：' + item.GSCode;
                },
                updater: function (item) {
                    var item = JSON.parse(item);
                    $('#GSID').val(item.GSID);
                    return item.GSName;
                }
            });

            //用于记录页数
            var page = 1;
            //用于记录每页多少条记录
            var size = 20;

            var isCreate = true;
            var SSID = 0;

            //初始化按钮
            commonUtil.loadBtnList(ModuleID, function () {
                rScroll();
                $('#editBtn').attr('disabled', 'disabled');
                $('#deleteBtn').attr('disabled', 'disabled');
            });
            //加载信息列表
            var loadList = function (page) {
                if ($('.footable thead').children().size() == 0)
                    tableControl.initThead2('.footable', ['图片', '店铺编号', '店铺名称', '货架编号', '货架名称', '货架数量', '是否有效']);

                pageControl.init('ShopShelf', 'GetList', {
                    Keys: $(".search-keys").val(),
                    IsRemove: $('#isRemove').val(),
                    Page: page,
                    //                  Size: size,
                    alwaysCallBack: function () {
                        SSID = 0;
                        $('#editBtn').attr('disabled', 'disabled');
                        $('#deleteBtn').attr('disabled', 'disabled');
                    }
                }, function (result) {
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            result.data.Items.map(function (item, i) {
                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                    children: [
                                        { tdText: item.SSID, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
                                        { tdText: '', c: 0, r: 0, tdHtml: '<a class="fancybox" href="' + item.ImageUrl + '" title="' + item.ShopName + '"><img alt="image" src="' + item.ImageUrl + '" class="itemPic" /></a>', tdId: '', tdClass: '' },
                                        { tdText: (item.ShopCode || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                        { tdText: (item.ShopName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                        { tdText: (item.GSCode || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                        { tdText: (item.GSName || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                        { tdText: (item.Qty || ' '), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                                        { tdText: (item.IsRemove ? ' 无效 ' : ' 有效 '), c: 0, r: 0, tdHtml: ('<i class="fa fa-' + (!item.IsRemove ? 'check text-navy' : 'times text-danger') + '"></i>'), tdId: '', tdClass: '' },
                                    ]
                                };
                                tBody.push(tempTr);
                            })
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 8, null);
                });
            }
            loadList(1);

            //新增按钮
            $('.btns-container').on('click', '#addBtn', function () {
                isCreate = true;
                $('.editTitle').text('新增-店铺货架信息');
                $('#Qty').val('');
                $('#shopSearch').val('');
                $('#ShopCode').val('');
                $('#ShopName').val('');
                $("#GSID").val('');
                $("#GSText").val('');
            });
            //编辑按钮
            $('.btns-container').on('click', '#editBtn', function () {
                isCreate = false;
                $('.editTitle').text('编辑-店铺货架信息');
                loadDetail(SSID);
            });
            $('.btns-container').on('click', '#btn-search', function () {
                loadList(1);
            });

            commonUtil.initDeleteBtnEvent({
                callBack: function () {
                    Y.API2('ShopShelf', 'Remove', { ID: SSID }, function (data) {
                        layer.closeAll('dialog');
                        if (data.Success == false) {
                            swal('删除失败', data.Message, 'error');
                        } else {
                            swal('删除成功', '该信息已被你永久删除', 'success');
                            loadList(1);
                        }
                    });
                }
            });

            var loadDetail = function (SID) {
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ShopShelf', 'GetID', { ID: SID }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        $('#Qty').val(data.Qty);
                        $('#shopSearch').val(data.ShopName);
                        $('#ShopCode').val(data.ShopCode);
                        $('#ShopName').val(data.ShopName);
                        $('#GSText').val(data.GSName);
                        $("#GSID").val(data.GSID);
                    }
                });
            }

            //选中记录
            $('#pageList').on('click', 'tr', function () {
                var sid = $(this).find('td:first').text();
                if (SSID == parseInt(sid))
                    return false;
                SSID = parseInt(sid);
                if (!isNaN(SSID))
                    $('#editBtn,#deleteBtn').removeAttr('disabled');
                $('.footable tr').removeClass('check');
                $(this).addClass('check');
            });

            //批量添加任务
            $(".btns-container").on("click", '#importBtn', function () {
                $.ImportExcelTemplate({
                    filetype: 'Shopshelf', filename: '店铺货架明细表', action: 'ImportTemplate', after: function () {
                        //回调方法
                        loadList(1);
                    }
                });
            });

            //保存基本信息(新增或编辑)
            $('#addModuleBtn').click(function () {
                if (!CheckDataValid('#checkModuleForm')) {
                    return false;
                }
                if ($('#ShopName').val() == '' || $('#ShopCode').val() == '') {
                    swal('输入的店铺名称无效');
                    return false;
                }
                if ($('#GSID').val() == '') {
                    swal('输入的货架无效');
                    return false;
                }
                //检验通过后执行新增或者编辑
                var deal = '';
                var successText = '';
                if (isCreate) {
                    deal = 'Create';
                    successText = '新增成功';
                } else {
                    deal = 'Modify';
                    successText = '编辑成功';
                }
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('ShopShelf', deal, {
                    SSID: SSID,
                    ShopCode: $('#ShopCode').val(),
                    ShopName: $('#ShopName').val(),
                    GSID: $('#GSID').val(),
                    Qty: $('#Qty').val()
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框
                        $('#closeAddBox').click();
                        //刷新列表
                        loadList(1);
                    }
                })
            })

            //导出按钮
            $(".btns-container").on("click", '#exportBtn', function () {
                var conditionsArr = [];
                var Keys = $(".search-keys").val();
                if (!Y.checkNull(Keys)) {
                    conditionsArr.push({ connector: "and", column: "(ss.shopcode", operator: "like", value: Keys, });
                    conditionsArr.push({ connector: "or", column: "ss.shopname", operator: "like", value: Keys });
                }
                conditionsArr = JSON.stringify(conditionsArr);
                var tempParam = {};
                tempParam.filename = "店铺货架明细表";
                tempParam.filetype = "Shopshelf";
                tempParam.conditions = encodeURIComponent(conditionsArr);
                tempParam.after = function () {
                    //回调方法
                    swal("导出成功!");
                }
                $.Export(tempParam);
            });
        })
    </script>
</asp:Content>

